<template>
    <div class="container containerSeckill">
        <!-- header -->
        <div class="header">
            <div class="header-box">
                <p class="header-title">商品名称:</p>
                <el-input
                    v-model="keword"
                    suffix-icon="el-icon-search"
                    size="small"
                    clearable
                    placeholder="输入要搜索的内容"
                    class="cont-ipt"
                    @change="getTableData(1)"
                    @keyup.native.enter="getTableData(1)"
                />
            </div>
            <div class="header-box">
                <p class="header-title header-right">审核状态:</p>
                <el-select
                    v-model="examine"
                    filterable
                    placeholder="请选择"
                    size="small"
                    @change="getTableData(1)"
                >
                    <el-option
                        v-for="item in examineList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </div>
            <div class="header-box">
                <p class="header-title header-right">是否已加入秒杀列表:</p>
                <el-select
                    v-model="isSeckill"
                    filterable
                    placeholder="请选择"
                    size="small"
                    @change="getTableData(1)"
                >
                    <el-option
                        v-for="item in SeckillList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </div>
            <div class="header-box">
                <p class="header-title header-right">商品创建日期:</p>
                <el-date-picker
                    v-model="creattime"
                    type="date"
                    size="small"
                    placeholder="选择日期"
                    @change="fnGetCreatTime"
                />
            </div>
            <div class="header-box">
                <p class="header-title">店铺名称:</p>
                <el-input
                    v-model="shopTitle"
                    placeholder="输入要搜索的内容"
                    class="cont-ipt"
                    @change="getTableData(1)"
                    clearable
                    suffix-icon="el-icon-search"
                    size="small"
                    @keyup.native.enter="getTableData(1)"
                />
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="seckillTable"
            @sort-change="handleSortChanged"
            @select="fnSelect"
            @select-all="fnSelectAllTop"
            @selection-change="handleSelectionChange"
        >
            <el-table-column
                type="selection"
                fixed="left"
            />
            <el-table-column
                prop="goods_title"
                label="商品名称"
                fixed="left"
                align="center"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="goods_cover"
                width="110px"
                label="商品缩略图"
            >
                <template slot-scope="scope">
                    <img
                        :src="scope.row.goods_cover"
                        class="img-cover"
                    >
                </template>
            </el-table-column>
            <el-table-column
                prop="goods_no"
                label="商品编号"
                width="150px"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="shop.shop_title"
                label="店铺名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="goods_price"
                label="秒杀价"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="goods_price_origin"
                label="原价"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                label="佣金"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <el-popover
                        placement="bottom"
                        trigger="hover"
                    >
                        <div
                            class="spec-list"
                            v-if="scope.row.specList"
                        >
                            <div
                                class="spec-line"
                                v-for="(specItem, specIndex) in scope.row.specList"
                                :key="specIndex"
                            >
                                {{ specItem | specFilter }}
                            </div>
                        </div>
                        <el-button
                            slot="reference"
                            type="text"
                            @mouseover.native="getProduct(scope.row)"
                        >
                            查看
                        </el-button>
                    </el-popover>
                </template>
            </el-table-column>
            <el-table-column
                prop="stock"
                label="剩余库存"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    {{ scope.row.stock }}
                </template>
            </el-table-column>
            <el-table-column
                prop="flash_sale_sale_num"
                label="总销量"
                width="110px"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                sortable="custom"
            />
            <el-table-column
                prop="create_time"
                label="创建日期"
                width="100px"
                :formatter="emptyFormatter"
                sortable="custom"
            >
                <template slot-scope="scope">
                    {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="audit_status"
                label="审核状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <span v-if="scope.row.audit_status == 1">已通过</span>
                    <span v-if="scope.row.audit_status == -1">未通过</span>
                    <span v-if="scope.row.audit_status == 0">待审核</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="flash_sale_count"
                label="是否已加入秒杀"
                width="150px"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <span v-if="Number(scope.row.flash_sale_count) > 0">是</span>
                    <span v-if="Number(scope.row.flash_sale_count) <= 0">否</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="flash_sale_view_count"
                label="真实总浏览量"
                width="140px"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                sortable="custom"
            />
            <el-table-column
                prop="flash_sale_view_count"
                label="企业主浏览量"
                width="110px"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    {{ scope.row.flash_sale_view_count + scope.row.flash_sale_view_count_auto }}
                </template>
            </el-table-column>
            <el-table-column
                label="秒杀记录"
                width="110px"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        :disabled="Number(scope.row.flash_sale_count) == 0 "
                        @click="fngetScekillList(scope.row)"
                    >
                        {{ scope.row.flash_sale_count }}
                    </el-button>
                </template>
            </el-table-column>
            <el-table-column
                prop="goods_buy_limit_count"
                label="限购次数"
                width="110px"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    {{ scope.row.goods_buy_limit_count == -1 ? '不限制' : scope.row.goods_buy_limit_count }}
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                fixed="right"
                width="200px"
            >
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        @click='fnUpperShelf(scope.row, 1)'
                        :disabled="scope.row.audit_status == 1 "
                    >
                        通过
                    </el-button>
                    <el-button
                        type="text"
                        @click='fnUpperShelf(scope.row, -1)'
                        :disabled="scope.row.audit_status == -1 "
                    >
                        不通过
                    </el-button>
                    <el-button
                        type="text"
                        @click='fnShopEdit(scope.row)'
                    >
                        编辑
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- 秒杀记录 -->
        <el-dialog
            :visible.sync="DialogVisibleList"
            width="760px"
            class="seckillDialogVisible"
        >
            <el-table
                :data="scekillResultList"
                height="100%"
                style="width: 100%;"
                border
            >
                <el-table-column
                    label="序号"
                    type="index"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="start_time"
                    label="日期"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.start_time * 1000 | dateFormatter('yyyy/MM/dd') }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="start_time"
                    label="时间"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.start_time * 1000 | dateFormatter('HH:mm') }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="goods_num"
                    label="开始库存"
                    show-overflow-tooltip
                />
                <el-table-column
                    prop="sale_num"
                    label="本场销量"
                    show-overflow-tooltip
                />
                <el-table-column
                    prop="view_count"
                    label="本场浏览量"
                    show-overflow-tooltip
                />
            </el-table>
        </el-dialog>
        <!-- /秒杀记录 -->

        <!-- 排入秒杀 -->
        <el-dialog
            :visible.sync="seckillDialogVisible"
            width="430px"
            center
        >
            <el-form
                :model="ruleForm"
                :rules="rules"
                ref="ruleForm"
                label-width="100px"
                class="demo-ruleForm"
            >
                <el-form-item
                    label="选择日期"
                    prop="scekillData"
                >
                    <el-date-picker
                        v-model="ruleForm.scekillData"
                        type="date"
                        size="small"
                        placeholder="选择秒杀日期"
                        @change="fnGetSckillDate"
                    />
                </el-form-item>
                <el-form-item
                    label="选择时间"
                    prop="scekillTime"
                >
                    <el-select
                        v-model="ruleForm.scekillTime"
                        placeholder="选择秒杀时间"
                        size="small"
                    >
                        <el-option
                            v-for="(item,index) in scekillTimeList"
                            :key="index"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button
                        size="small"
                        class="scekillrel"
                        @click="resetForm('ruleForm')">取消</el-button>
                    <el-button
                        type="primary"
                        size="small"
                        class="scekillbtn"
                        @click="submitForm('ruleForm')">确定</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <!-- /排入秒杀 -->

        <!-- 审核不通过 -->
        <el-dialog
            title="*请认真填写不通过的理由*"
            width="530px"
            custom-class="schedule-dialog"
            :visible.sync="showDilog"
        >
            <el-form
                :model="ruleFormReason"
                :rules="rulesReason"
                ref="ruleFormReason"
            >
                <el-form-item
                    prop='text'
                >
                    <el-input
                        type="textarea"
                        :autosize="{ minRows: 2, maxRows: 6}"
                        placeholder="不通过理由"
                        v-model="ruleFormReason.text"
                    />
                </el-form-item>
            </el-form>
            <div
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    size="small"
                    type="primary"
                    @click="submitFormReason('ruleFormReason')">提交</el-button>
            </div>
        </el-dialog>
        <!-- /审核不通过 -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-checkbox
                v-model="checkedAll"
                :indeterminate="checkIndeterminate"
                @change="fnChangeChecked">全选</el-checkbox>
            <el-button
                size="mini"
                type="text"
                :disabled="multipleSelection.length == 0 ? true : false"
                @click="fnDischargeScekill"
            >排入秒杀</el-button>
            <el-button
                size="mini"
                type="text"
                :disabled="multipleSelection.length == 0 ? true : false"
                @click="fnExamineShop"
            >批量审核通过</el-button>
            <el-pagination
                background
                layout="total, prev, pager, next"
                :total="page.total_count"
                :page-size="page.page_size"
                :current-page="page.now_page"
                @current-change="getTableData"
            />
        </div>
    </div>
</template>

<script>
/**
 * @param {string}  keword //商品名称
 * @param {string}  shopTitle //商品标题
 * @param {String}  examine //审核状态
 * @param {String}  isSeckill//是否加入秒杀列表
 * @param {String}  creattime//创建时间
 * @param {String}  time//创建时间时间戳
 * @param {Boolean} seckillDialogVisible //弹窗状态
 * @param {Boolean} checkedAll //选中状态
 * @param {String}  checkIndeterminate //选中显示状态
 * @param {Array}   multipleSelection //选中数据
 * @param {Object}  ruleForm //弹窗字段
 * @param {Object}  rules //弹窗验证字段
 * @param {String}  scekillData //秒杀日期
 * @param {String}  scekillTime //秒杀日期
 * @param {Array}   tableData //表单数据
 * @param {Object}  page //分页
 * @param {Object}  filterData  //排序
 * @param {Array}   scekillResultList  //秒杀记录列表
 * @param {Boolean} DialogVisibleList  //秒杀记录列表弹窗开关
 * @param {Array}   scekillTimeList  //秒杀时间数据
 * @param {Boolean} showDilog  //审核不通过理由
 * @param {String}  goods_no  //商品编号，用于审核不通过
 * @param {String}  indexSucess  //计算排入秒杀成功个数
 * @param {String}  indexError  //计算排入秒杀失败个数
 */
export default {
    data () {
        return {
            keword: '',
            shopTitle: '',
            time: '',
            examine: 99,
            isSeckill: 99,
            creattime: '',
            scekillResultList: [],
            DialogVisibleList: false,
            seckillDialogVisible: false,
            checkedAll: false,
            checkIndeterminate: false,
            scekillTimeList: [],
            multipleSelection: [],
            showDilog: false,
            goods_no: '',
            ruleFormReason: {
                text: ''
            },
            rulesReason: {
                text: [
                    { required: true, message: '请填写不通过理由', trigger: 'blur' }
                ]
            },
            ruleForm: {
                scekillData: '',
                scekillTime: '',
            },
            rules: {
                scekillData: [
                    { required: true, message: '请选择日期', trigger: 'blur' }
                ],
                scekillTime: [
                    { required: true, message: '请选择时间', trigger: 'blur' }
                ]
            },
            examineList: [{
                value: 99,
                label: '全部'
            },{
                value: 0,
                label: '待审核'
            },{
                value: -1,
                label: '未通过'
            },{
                value: 1,
                label: '已通过'
            }],
            SeckillList: [{
                value: 99,
                label: '全部'
            },{
                value: 1,
                label: '是'
            },{
                value: 0,
                label: '否'
            }],
            tableData: [],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            filterData: {
                sort_field: 0,
                sort_type: 0
            },
            indexSucess: 0,
            indexError: 0,
            tableDataCopy: []
        };
    },
    filters: {
        specFilter(val){
            if(!val){
                return '--';
            }
            let str = '';

            for(var i in val.spec_list){
                str += val.spec_list[i].spec_name + ':' + val.spec_list[i].spec_value;
                if(i < val.spec_list.length){
                    str += ',';
                }else{
                    str += ': ';
                }
            }

            if(str){
                str += '佣金' + val.product_commission+'元';
            }
            return str;
        }
    },
    watch: {
        // 关闭弹窗清空数据
        DialogVisibleList (val) {
            if (!val) {
                setTimeout(()=>{
                    this.scekillResultList = [];
                },300);
            }
        },
        showDilog (val) {
            if (!val) {
                this.ruleFormReason = {
                    text: ''
                };
                this.goods_no = '';
            }
        },
        seckillDialogVisible (val) {
            if (!val) {
                this.$refs['ruleForm'].resetFields();
                this.scekillTimeList = [];
            }
        }
    },
    created () {
        //前100商品匹配
        if(this.$route.query.title) {
            this.keword = this.$route.query.title;
        }

        this.setHeader();
        this.getTableData();
        this.getList();
    },
    methods: {
        /**
         * 设置表单header
         */
        setHeader () {
            this.$store.commit('SET_HEADER', [{
                title: "APP后台",
            },
            {
                title: '商城'
            },
            {
                title: '秒杀'
            },
            {
                title: "秒杀商品"
            }]
            );
        },

        /**
         * 获取商品规格信息
         */
        getProduct (row) {
            this.$post('/student/shop_goods%5Cget', {
                goods_no: row.goods_no
            }, resp=> {
                if (resp.code == 1) {
                    let spec = resp.data.goods_product_list;

                    this.$set(row, 'specList', spec);
                } else if (resp.code == 0) {
                    return;
                }
            });
        },

        /**
         * 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/shop_goods_flash_sale%5Cget_goods_list', {
                page_id: page || this.page.now_page,
                goods_title: this.keword,
                shop_title: this.shopTitle,
                create_day_time: this.time / 1000,
                audit_status: this.examine,
                set_flash_sale: this.isSeckill,
                sort_field: this.filterData.sort_field,
                sort_type: this.filterData.sort_type
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                    this.$refs.seckillTable.doLayout();
                }
            });
        },

        /**
         * 处理秒杀记录数据
         */
        fngetScekillList (row) {
            this.$post('/student/shop_goods_flash_sale%5Cget_goods_flash_sale_list', {
                goods_no: row.goods_no
            },resp=> {
                if (resp.code == 1) {
                    resp.data.list.map(item=>{
                        if (item.status == 3) {
                            this.scekillResultList.push({
                                start_time: item.start_time,
                                goods_num: item.goods_num,
                                view_count_auto: item.view_count_auto,
                                view_count: item.view_count,
                                sale_num: item.sale_num,
                                sale_num_auto: item.sale_num_auto
                            });
                        }
                    });
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'waring',
                        message: resp.msg
                    });
                }
            });
            this.DialogVisibleList = !this.DialogVisibleList;
        },

        /**
         * 商品创建日期选择处理
         */
        fnGetCreatTime () {
            let time = this.fnGeTtimeStamp(this.creattime);

            this.time = time;
            this.getTableData(1);
        },

        /**
         * 获取选择日期时间戳
         */
        fnGeTtimeStamp (no) {
            let year = new Date(no).getFullYear(),
                month = new Date(no).getMonth()+1,
                day = new Date(no).getDate();
            let data = this.setDate(year) + '-' + this.setDate(month) + '-' + this.setDate(day);
            let time = new Date(data).getTime();

            return time;
        },

        /**
         *  日期补0
         */
        setDate (param) {
            return param < 10 ? '0' + param : param;
        },

        /**
         * 提交不通过理由
         */
        submitFormReason (formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.$post('/student/shop_goods_flash_sale%5Caudit', {
                        goods_no: this.goods_no,
                        audit_status: -1,
                        reason: this.ruleFormReason.text
                    }, resp=> {
                        if (resp.code == 1) {
                            this.showDilog = !this.showDilog;
                            this.getTableData();
                            this.$message({
                                type: 'success',
                                message: '操作成功'
                            });
                        } else if (resp.code == 0) {
                            this.$message({
                                type: 'waring',
                                message: resp.msg
                            });
                        }
                    });
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },

        /**
         * 审核通过/不通过
         */
        fnUpperShelf (row, status) {
            let audit = status == 1 ? 1 : -1;

            if (audit == 1) {
                this.$post('/student/shop_goods_flash_sale%5Caudit', {
                    goods_no: row.goods_no,
                    audit_status: audit
                }, resp=> {
                    if (resp.code == 1) {
                        this.$set(row, 'audit_status', 1);
                        this.getTableData();
                        this.$message({
                            type: 'success',
                            message: '操作成功'
                        });
                    } else if (resp.code == 0) {
                        this.$message({
                            type: 'waring',
                            message: resp.msg
                        });
                    }
                });
            } else {
                this.goods_no = row.goods_no;
                this.showDilog = !this.showDilog;
            }
        },

        /**
         * 编辑/跳转企业主后台
         */
        fnShopEdit (row) {
            let nowTime = this.fnGetNowTime(),
                arr = [];

            this.tableDataCopy.map(item=>{
                item.newArr.map(itm=>{
                    if (itm.goods_no == row.goods_no ) {
                        arr.push(
                            item.start_time * 1000,
                            item.end_time * 1000
                        );
                    }
                });
                return false;
            });

            if (Number(nowTime) >= Number(arr[0]) && Number(nowTime) <= Number(arr[1])) {
                this.$message({
                    type: 'waring',
                    message: '场次正在进行中，不可以编辑'
                });
                return;
            }

            let url = '';

            this.$post('/wei4/hire_user%5Cget_login_session_ticket', {
                hire_no: row.hire_no
            }, resp => {
                if (resp.code == 1) {
                    window.open(`${this.$shopBaseUrl}/manage/market/good-editSeckill?no=${row.goods_no}&session_ticket=${resp.data.session_ticket}`);
                    // if(window.location.host == 'phaadmin.wxhand.com') {
                    //     url = `http://cms.zsdx.cn/manage/market/good-editSeckill?no=${row.goods_no}&session_ticket=${resp.data.session_ticket}`;
                    //
                    //     window.open(url);
                    // }else{
                    //     url = `http://gt.wxhand.com/manage/market/good-editSeckill?no=${row.goods_no}&session_ticket=${resp.data.session_ticket}`;
                    //
                    //     window.open(url);
                    // }
                } else {
                    this.$message({
                        type: 'warning',
                        message: resp.msg,
                        center: true
                    });
                }
            });
        },

        /**
         * 获取选择日期时间戳/后期封装/
         */
        fnGetNowTime () {
            let no = new Date().getTime();
            let year = new Date(no).getFullYear(),
                month = new Date(no).getMonth()+1,
                day = new Date(no).getDate(),
                Hous = new Date(no).getHours(),
                Minus = new Date(no).getMinutes(),
                Sce = new Date(no).getSeconds();
            let date = this.setDate(year) + '-' + this.setDate(month) + '-' + this.setDate(day) + ' ' + this.setDate(Hous) + ':' + this.setDate(Minus) + ':' + this.setDate(Sce);

            let time = new Date(date).getTime();

            return time;
        },

        /**
         * 获取当天秒杀场次及商品/编辑判断（不是当场的场次就可以编辑）
         */
        getList () {
            let time = this.fnGeTtimeStamp(new Date().getTime());

            this.$post('/student/shop_goods_flash_sale%5Cget_list', {
                day_time: time / 1000,
                time_no: ''
            }, resp => {
                if (resp.code == 1) {
                    let arr = [],
                        data = [],
                        newArr = [];

                    data.push(resp.data);
                    data.map(item=> {
                        item.time_list.map((list,index)=>{
                            arr.push({
                                start_time: list.start_time,
                                end_time: list.end_time,
                                time_no: list.time_no,
                                newArr: ''
                            });
                            for(let i in item.time_goods_map) {

                                if (i == list.time_no ) {
                                    arr[index].newArr = item.time_goods_map[i];
                                    /* 商品数据为空处理 */
                                    if (JSON.stringify(item.time_goods_map[i]) !== '[]') {
                                        arr[index].newArr = item.time_goods_map[i];
                                    }
                                }
                            }
                            return;
                        });
                    });

                    arr.map((item,index)=>{
                        if (item.newArr !== '') {
                            newArr.push(item);
                        }
                        return;
                    });

                    this.tableDataCopy = newArr;
                }
            });
        },

        /**
         * 排入秒杀
         */
        fnDischargeScekill () {
            this.seckillDialogVisible = !this.seckillDialogVisible;
        },

        /**
         * 批量审核通过
         */
        fnExamineShop () {
            this.multipleSelection.map(item=> {
                this.$post('/student/shop_goods_flash_sale%5Caudit', {
                    goods_no: item.goods_no,
                    audit_status: 1
                }, resp=> {
                    if (resp.code == 1) {
                        this.indexSucess ++;
                    } else if (resp.code == 0) {
                        this.indexError ++;
                    }
                });
            });
            this.getTableData();

            setTimeout(()=>{
                if (this.indexError > 0) {
                    this.$message({
                        type: 'waring',
                        message: `${this.indexError}个商品审核失败`
                    });
                } else {
                    this.$message({
                        type: 'success',
                        message: '批量审核成功'
                    });
                }
                this.indexSucess = this.indexError = 0;
            },500);

        },

        /**
         * 时间戳转时+分
         */
        getHous (time) {
            let Hous = new Date(time * 1000).getHours(),
                Minus = new Date(time * 1000).getMinutes(),
                Sce = new Date(time * 1000).getSeconds();

            return this.setDate(Hous) + ':' + this.setDate(Minus) + ':' + this.setDate(Sce);
        },

        /**
         * 排入秒杀日期选择
         */
        fnGetSckillDate () {
            let time = this.fnGeTtimeStamp(this.ruleForm.scekillData);

            if (time) {
                this.scekillTimeList = [];
                this.ruleForm.scekillTime = '';
                this.$post('/student/shop_goods_flash_sale%5Cget_simple_time_list', {
                    day_time: time / 1000
                }, resp=> {
                    if (resp.code == 1) {
                        if (resp.data.list.length == 0) {
                            this.$message({
                                type: 'waring',
                                message: '当前日期暂无排期'
                            });
                            return;
                        }
                        resp.data.list.map(item=>{
                            this.scekillTimeList.push({
                                value: item.time_no,
                                label: this.getHous(item.start_time) + ' - ' + this.getHous(item.end_time)
                            });
                        });
                    } else if (resp.code == 0) {
                        this.$message({
                            type: 'waring',
                            message: resp.msg
                        });
                    }
                });
            }
        },

        /**
         * 确定排入秒杀
         */
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.multipleSelection.map(item=> {
                        this.$post('/student/shop_goods_flash_sale%5Cadd', {
                            goods_no: item.goods_no,
                            time_no: this.ruleForm.scekillTime
                        }, resp=> {
                            if (resp.code == 1) {
                                this.indexSucess++;
                            } else if (resp.code == 0) {
                                this.indexError++;
                            }
                        });
                    });

                    this.seckillDialogVisible = !this.seckillDialogVisible;
                    this.getTableData();

                    setTimeout(()=>{
                        if (this.indexError > 0) {
                            this.$message({
                                type: 'waring',
                                message: `${this.indexError}个商品排期失败`
                            });
                        } else {
                            this.$message({
                                type: 'success',
                                message: '排期成功'
                            });
                        }
                        this.indexSucess = this.indexError = 0;
                    },500);
                } else {
                    return false;
                }
            });
        },

        /**
         * 取消排入秒杀
         */
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.seckillDialogVisible = !this.seckillDialogVisible;
        },

        /**
         * 选择Checkbox
         */
        fnSelect(selection) {
            if(selection.length == this.tableData.length) {
                this.checkedAll = true;
            }else{
                this.checkedAll = false;
            }

            // 改变全选checkbox 的显示状态
            if(selection.length > 0 && selection.length < this.tableData.length) {
                this.checkIndeterminate = true;
            }else{
                this.checkIndeterminate = false;
            }
        },
        fnSelectAllTop(selection) {
            if(selection.length > 0) {
                this.checkedAll = true;
            }else{
                this.checkedAll = false;
            }

            // 改变全选checkbox 的显示状态
            if(selection.length > 0 && selection.length < this.tableData.length) {
                this.checkIndeterminate = true;
            }else{
                this.checkIndeterminate = false;
            }
        },
        fnChangeChecked() {
            if(this.checkedAll){
                this.toggleSelection(1);
            }else{
                this.toggleSelection();
            }
        },
        toggleSelection(rows) {
            if (rows) {
                this.$refs.seckillTable.toggleAllSelection();
            } else {
                this.$refs.seckillTable.clearSelection();
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },

        /**
         * 排序
         */
        handleSortChanged(data) {
            let sortTypeMap = {
                ascending: 0,
                descending: 1
            };

            let sortFieldMap = {
                create_time: 0,
                flash_sale_sale_num: 1,
                flash_sale_view_count: 2
            };

            if (data.order) {
                this.filterData.sort_field = sortFieldMap[data.prop];
                this.filterData.sort_type = sortTypeMap[data.order];
            } else {
                this.filterData.sort_field = '';
                this.filterData.sort_type = '';
            }

            this.getTableData();
        },

        /**
         * 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) {
                return '--';
            }
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        overflow: hidden;
        .header {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            color: #606266;
            .header-box {
                display: flex;
                align-items: center;
                margin-right: 20px;
                margin-bottom: 20px;
            }
            .header-title {
                margin-left: 25px;
                white-space: nowrap;
            }
            .header-right {
                margin-right: 10px;
            }
            .header-title:first-child{
                margin-left: 0;
            }
            .cont-ipt {
                width: 180px;
                margin-left: 10px;
            }
            .header-right {
                display: flex;
                .el-button {
                    margin-left: 20px;
                }
            }
        }
        .img-cover {
            width: 60px;
            height: 60px;
        }
        .curse-add {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        .pagination-wrapper {
            padding-top: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
        .dialog-footer {
            display: flex;
            justify-content: center;
            align-items: center;
        }
    }
    .switch-fixed {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        right: 0;
        margin: auto;
        z-index: 999;
        cursor: pointer;
    }
    .scekillrel {
        margin-left: -30px;
        margin-top: 10px;
    }
    .scekillbtn {
        margin-left: 120px;
        margin-top: 10px;
    }
</style>
<style lang="less">
    .containerSeckill .el-table__body-wrapper .el-table__body .el-table__row td {
        border-right: none;
    }
    .containerSeckill .el-table__header-wrapper .el-table__header .has-gutter tr th {
        border-right: none;
    }
    .containerSeckill .el-table .el-table_1_column_6  .cell {
        position: relative;
    }
    .seckillDialogVisible .el-dialog__body .el-table__body-wrapper {
        height: 400px;
    }
    .seckillDialogVisible .el-dialog__body .el-table::-webkit-scrollbar {
        width: 4px;
    }
</style>
